<%@ page contentType="text/html; charset=iso-8859-1" 
language="java" import="java.io.*,java.util.*,java.net.*,java.sql.*, javax.servlet.http.*" errorPage="" %>
<%@ include file="conexion.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Title      : Transition
Version    : 1.0
Released   : 20070703
Description: A two-column, fixed-width template with light color blend.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Web de Cultura de Aplicaciones Telematicas 3</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
	<div id="logo">
		<h1><a href="#">eCultura</a></h1>
		<h2><a href="http://www.upf.edu/">Powered by UPF</a></h2>
	</div>
	<div id="topmenu">
		<ul>
			<li class="first"><a href="index.jsp">Inicio</a></li>
			<li><a href="mailto:at3@upf.edu">Contacto</a></li>
		</ul>
	</div>
</div>
<div id="header2">
	<div id="menu">
		<ul>
			<li class="first"><a href="index.jsp">Home</a></li>
			<li><a href="cine.jsp">Cine</a></li>
			<li><a href="teatro.jsp">Teatro</a></li>
			<li><a href="musica.jsp">M&uacute;sica</a></li>
			<li><a href="espectaculos.jsp">Espectaculos</a></li>
		</ul>
	</div>
	<div id="splash"><a href="#"><img src="images/falas2.jpg" alt="" width="560" height="200" /></a></div>
</div>
<hr />
<div id="page">
	<div id="content">
		<div>
			<%
			Connection canal = null;
			Statement instruccion = null;
			ResultSet tabla = null;
			String conexion = dburlMysql()+dbhostMysql()+"/"+dbnameMysql()+"?user="+usuarioMysql()+"&password="+passwordMysql();
			boolean usuario = false;
			//Abrir el enlace
			try{
				Class.forName(dbdriverMysql()).newInstance();
				canal = DriverManager.getConnection(conexion);
				instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
			}catch(ClassNotFoundException e){ 
				out.println(e);
			}catch(SQLException e){
				out.println(e);
			}
			
			try{
				tabla = instruccion.executeQuery("SELECT notice_title, notice_subtitle, notice_body FROM notices WHERE notice_type LIKE 'espectaculos' ORDER BY notice_id DESC LIMIT 5;");
				while(tabla.next()){
					out.println("<h1 class=\"title\">"+tabla.getString(1)+"</h1>");
					out.println("<div class=\"content\"><h3>"+tabla.getString(2)+"</h3>");
					out.println("<p align=\"justify\">"+tabla.getString(3)+"</p></div>");				
				}
			}catch(Exception e){ 
				out.println(e);
			}%>
		</div>
	</div>
	<div id="sidebar">
		<ul>
			<%
Cookie[] cookies = request.getCookies();
if (cookies == null) { %>
<li>
					<h2>Cuenta de Usuario</h2>
					<ul>
						<form id="form1" method="post" action="servlet/coreservlets.Listar">
							<label for="inputtext1">Login:</label><br />
							<input id="inputtext1" type="text" name="login" /><br />
							<label for="inputtext2">Password:</label><br />
							<input id="inputtext2" type="password" name="password" /><br />
							<input id="inputsubmit1" type="submit" name="boton" value="Entrar" /><br />
							<input id="inputsubmit2" type="submit" name="boton" value="Registrarse"/>
						</form>
					</ul>
				</li>
<%} else if(cookies.length >= 1 ){ 
	boolean b = false;
	for (Cookie c : cookies){
		if(c.getName().equalsIgnoreCase("Cookie-eCultura-Indentification")){
			String[] s = c.getValue().split("-"); 
			usuario = true;%>
			<li>
				<h2>Bienvenido <%=s[3]%></h2>
				<ul>
					<form id="form2" method="post" action="servlet/coreservlets.Listar">
						<label for="inputsubmit2">Pulsar para desconectar:</label>
						<input id="inputsubmit2" type="submit" name="boton" value="Desconectar" />
					</form>
				</ul>
			</li>
			<%
			b = true;
			break;
		}
	}
	if(!b){ %>
	<li>
					<h2>Cuenta de Usuario</h2>
					<ul>
						<form id="form1" method="post" action="servlet/coreservlets.Listar">
							<label for="inputtext1">Login:</label><br />
							<input id="inputtext1" type="text" name="login" /><br />
							<label for="inputtext2">Password:</label><br />
							<input id="inputtext2" type="password" name="password" /><br />
							<input id="inputsubmit1" type="submit" name="boton" value="Entrar" /><br />
							<input id="inputsubmit2" type="submit" name="boton" value="Registrarse"/>
						</form>
					</ul>
				</li>
	<%}
} %>
			<li>
				<h2>&Uacute;ltimas Actualizaciones</h2>
				<ul>
					<%
					try{
						tabla = instruccion.executeQuery("SELECT notice_title, notice_subtitle, notice_type FROM notices ORDER BY notice_id DESC LIMIT 8;");
						while(tabla.next()){
							out.println("<li class=\"first\">");
							if(usuario){
								out.println("<h3><a href=\"../"+tabla.getString(3)+".jsp\">"+tabla.getString(1)+"</a></h3>");
							} else {
								out.println("<h3>"+tabla.getString(1)+"</h3>");
							}
							out.println("<p>"+tabla.getString(2)+"</p></li>");
						}
					}catch(Exception e){ 
						out.println(e);
					} finally {
						if (canal!=null){
							try{
								canal.close();
							} catch(SQLException sqle){
								out.println(sqle);
							}
						}
					}%>
				</ul>
			</li>
		</ul>
	</div>
	<div style="clear: both;">&nbsp;</div>
</div>
<hr />
<div id="footer-wrapper">
	<div id="footer">
		<p id="legal">Copyright &copy; 2007 Transition. All Rights Reserved<br />
			Designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
  </div>
</div>

<div style="font-size: 0.8em; text-align: center; margin-top: 1.0em; margin-bottom: 1.0em;">
Design downloaded from <a href="http://www.freewebtemplates.com/">Free Templates</a> - your source for free web templates
</div>
</body>
</html>
